<cfcomponent output="false" extends="validateThis.server.AbstractServerRuleValidator" hint="I am responsible for performing a check for unique user e-mail.">

	<cffunction name="validate" returntype="any" access="public" output="false" hint="I perform the validation returning info in the validation object.">
		<cfargument name="validation" type="any" required="yes" hint="The validation object created by the business object being validated." />
		<cfargument name="locale" type="string" required="yes" hint="The locale to use to generate the default failure message." />

        <cfscript>
            var args = [arguments.validation.getPropertyDesc()];
            var userGateway = new assets.calgrants.com.gateway.UserGateway();
            var userEmails = userGateway.query(Email = arguments.validation.getObjectValue());
            var i = 0;

            if(shouldTest(arguments.validation))
            {
                for(i = 1; i LTE userEmails.RecordCount; i = (i + 1))
                {
                    if(userEmails["Email"][i] EQ arguments.validation.getObjectValue() AND (userEmails["User_ID"][i] NEQ arguments.validation.getTheObject().getUser_ID()))
                    {
                        fail(arguments.validation,"A user already exists with this e-mail address.");
                        break;
                    }
                }
            }
        </cfscript>
	</cffunction>
	
</cfcomponent>
	

